import React, { Component } from 'react'
import {Link, BrowserRouter, Route, Routes, NavLink, Navigate} from 'react-router-dom'
import About from './components/About'
import Home from './components/Home'
import MyNavLink from './components/MyNavLink'
import './App.css'

export default class App extends Component {
  render() {
    return (
      <div>
        <div className="row">
          <div className="col-xs-offse6-2 col-xs-8">
            <div className="page-header">
              <h2>React Router Demo</h2>
            </div>
          </div>
        </div>
        <div className="row">
          <div className="col-sx-2 col-xs-offset-2">
            <div className="list-group">
              {/* 原生html中，靠<a>跳转不同的页面 */}
              {/* 在react中靠路由链接实现切换组件----编写路由链接 */}
                <MyNavLink to="/about">about</MyNavLink>
                <br/>
                <MyNavLink to="/home/a">home</MyNavLink>
                <br/>
                <NavLink to="/about" children="NavLink单标签用children属性作为内容"/>
            </div>
          </div>

          <div className="col-xs-6">
            <div className="panel">
              <div className="panel-body">
                {/* 注册路由 */}
                <Routes>
                  <Route path="/about" element={<About/>}/>
                  <Route path="/home/:subpath?" element={<Home/>}/>
                  {/* v6以下版本用redirect实现路由重定向 */}
                  {/* <Redirect to="/about" /> */}
                  {/* v6以上版本移除了Redirect，使用Navigate组件 */}
                  <Route path="/" element={<Navigate replace to="/about" />}/>
                  
                </Routes>
              </div>
            </div>
          </div>
        </div>
      </div>
    )
  }
}
